from datetime import datetime
import re
from typing import Union

from pydantic import BaseModel, Field, field_validator
from typing_extensions import Literal

from forward.utils.tools import ToolsUtil


class UserAuthSchema(BaseModel):
    id: int = Field(..., description="主键")
    user_id: int = Field(0, description="用户ID")
    openid: str = Field(..., description="Openid")
    unionid: str = Field(..., description="Unionid")
    client: int = Field(
        1,
        description="客户端类型: [1=微信小程序, 2=微信公众号, 3=手机H5, 4=电脑PC, 5=苹果APP, 6=安卓APP]",
    )
    created_time: datetime|None = Field(None, description="创建时间")
    updated_time: datetime|None = Field(None, description="更新时间")
    model_config = {
        "alias_generator": ToolsUtil.to_lower_camel,
        "populate_by_name": True,
    }


class UserSchema(BaseModel):
    """
    用户信息表
    """

    id: int = Field(..., description="主键")
    sn: int = Field(0, description="编号")
    avatar: str = Field(..., description="头像")
    real_name: str = Field(..., description="真实姓名")
    nickname: str = Field(..., description="用户昵称")
    username: str = Field(..., description="用户账号")
    password: str = Field(..., description="用户密码")
    mobile: str = Field(..., description="用户电话")
    salt: str = Field(..., description="加密盐巴")
    sex: int = Field(0, description="用户性别: [1=男, 2=女]")
    channel: int = Field(
        0,
        description="注册渠道: [1=微信小程序, 2=微信公众号, 3=手机H5, 4=电脑PC, 5=苹果APP, 6=安卓APP]",
    )
    is_disable: int = Field(0, description="是否禁用: [0=否, 1=是]")
    is_delete: int = Field(0, description="是否删除: [0=否, 1=是]")
    last_login_ip: str = Field(..., description="最后登录IP")
    last_login_time: datetime | None = Field(None, description="最后登录时间")
    model_config = {
        "alias_generator": ToolsUtil.to_lower_camel,
        "populate_by_name": True,
    }


